package com.lovi.common;

import lombok.Data;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 维护离线消息集合
 */
@Data
public class OfflineMessageMap {
    //离线消息集合
    private static ConcurrentHashMap<String, ArrayList<Message>> offLineMessageMap
            = new ConcurrentHashMap<>();

    //新增离线消息
    public static void addOffLineMessage(String userId, Message message){
        if(offLineMessageMap.containsKey(userId)){
            offLineMessageMap.get(userId).add(message);
        }else{
            ArrayList<Message> list = new ArrayList<>();
            list.add(message);
            offLineMessageMap.put(userId, list);
        }
    }
    //获取离线消息
    public static ArrayList<Message> getOffLineMessage(String userId){
        return offLineMessageMap.get(userId);
    }
    //移除离线消息
    public static void removeOffLineMessage(String userId){
        offLineMessageMap.remove(userId);
    }


}
